﻿CREATE PROCEDURE [dbo].[UpdateSecurityRole]
    @RoleId uniqueidentifier,
    @Name nvarchar(50),
	@IsDeleted bit,
    @LastChanged datetime,
	@LastChangedBy uniqueidentifier,

	@TimeStamp timestamp,
	@newTimeStamp timestamp output

AS

	UPDATE SecurityRole

	SET 
	 
	 Name = @Name,
	 IsDeleted = @IsDeleted, 
	 LastChanged = @LastChanged,
	 LastChangedBy = @LastChangedBy

	WHERE RoleId = @RoleId AND [TimeStamp]=@TimeStamp

  IF @@ROWCOUNT = 0

    RAISERROR('Row has been edited by another user', 16, 1)            	


	SELECT @newTimeStamp = [TimeStamp]

	FROM SecurityRole 

	WHERE RoleId = @RoleId

RETURN 0